package com.zmn.plat.business.impl.orderconfig.returnvisitcontent;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.plat.business.interfaces.orderconfig.returnvisitcontent.ReturnVisitContentBService;
import com.zmn.plat.model.entity.orderconfig.returnvisitcontent.ReturnVisitContent;
import com.zmn.plat.model.entity.orderconfig.returnvisitcontent.ReturnVisitContentQuery;
import com.zmn.plat.model.vo.orderconfig.returnvisitcontent.ReturnVisitContentVO;
import com.zmn.plat.services.interfaces.orderconfig.returnvisitcontent.ReturnVisitContentService;

/**
 * 类描述:回访内容ReturnVisitContentBServiceImpl
 *
 * @author linfeng
 * @since 2019/10/24/11:29
 */
@Service
public class ReturnVisitContentBServiceImpl implements ReturnVisitContentBService {
    private Logger logger = LoggerFactory.getLogger(ReturnVisitContentBServiceImpl.class);

    @Resource
    ReturnVisitContentService returnVisitContentService;

    @Override
    @SuppressWarnings("Duplicates")
    public List<ReturnVisitContentVO> listPageByQuery(ReturnVisitContentQuery query) {
        List<ReturnVisitContent> items = returnVisitContentService.listPageByQuery(query);
        List<ReturnVisitContentVO> returnVisitContentVOList = new ArrayList<>();
        for (ReturnVisitContent returnVisitContent : items) {
            ReturnVisitContentVO returnVisitContentVO = new ReturnVisitContentVO();
            BeanUtils.copyProperties(returnVisitContent, returnVisitContentVO);
            String[] platIds = returnVisitContent.getPlat().split(",");
            String platName = "";
            for (int i = 0; i < platIds.length; i++) {
                if (i < platIds.length - 1) {
                    platName += (GlobalConsts.getPlatName(Integer.valueOf(platIds[i])) + "、");
                } else {
                    platName += GlobalConsts.getPlatName(Integer.valueOf(platIds[i]));
                }
            }
            returnVisitContentVO.setPlatName(platName);
            returnVisitContentVOList.add(returnVisitContentVO);
        }

        return returnVisitContentVOList;
    }

    @Override
    @SuppressWarnings("Duplicates")
    public List<ReturnVisitContentVO> listByQuery(ReturnVisitContentQuery query) {
        List<ReturnVisitContent> items = returnVisitContentService.listByQuery(query);
        List<ReturnVisitContentVO> returnVisitContentVOList = new ArrayList<>();
        for (ReturnVisitContent returnVisitContent : items) {
            ReturnVisitContentVO returnVisitContentVO = new ReturnVisitContentVO();
            BeanUtils.copyProperties(returnVisitContent, returnVisitContentVO);
            String[] platIds = returnVisitContent.getPlat().split(",");
            String platName = "";
            for (int i = 0; i < platIds.length; i++) {
                if (i < platIds.length - 1) {
                    platName += (GlobalConsts.getPlatName(Integer.valueOf(platIds[i])) + "、");
                } else {
                    platName += GlobalConsts.getPlatName(Integer.valueOf(platIds[i]));
                }
            }
            returnVisitContentVO.setPlatName(platName);
            returnVisitContentVOList.add(returnVisitContentVO);
        }

        return returnVisitContentVOList;
    }

    @Override
    @SuppressWarnings("Duplicates")
    public ReturnVisitContentVO findByKey(Integer id) {
        ReturnVisitContent returnVisitContent = returnVisitContentService.findByKey(id);
        ReturnVisitContentVO returnVisitContentVO = new ReturnVisitContentVO();
        BeanUtils.copyProperties(returnVisitContent, returnVisitContentVO);
        String[] platIds = returnVisitContent.getPlat().split(",");
        String platName = "";
        for (int i = 0; i < platIds.length; i++) {
            if (i < platIds.length - 1) {
                platName += (GlobalConsts.getPlatName(Integer.valueOf(platIds[i])) + "、");
            } else {
                platName += GlobalConsts.getPlatName(Integer.valueOf(platIds[i]));
            }
        }
        returnVisitContentVO.setPlatName(platName);
        return returnVisitContentVO;
    }
}
